﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Draco.Algorithms
{
    //二维向量运算相关
    public class D_Vector2D
    {
        public static double Distance(int x1, int y1, int x2, int y2)
        {
            return Math.Sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
        }

        public static int SqrDistance(int x1, int y1, int x2, int y2)
        {
            return (x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2);
        }

        public static bool IsSameQuadrant(int xc, int yc, int x1, int y1, int x2, int y2)
        {
            //int q1, q2;
            //if (x1 - xc > 0 && y1 - yc > 0)         //第一象限  
            //    q1 = 1;
            //else if (x1 - xc < 0 && y1 - yc > 0)    //第二象限  
            //    q1 = 2;
            //else if (x1 - xc < 0 && y1 - yc < 0)    //第三象限  
            //    q1 = 3;
            //else                                    //第四象限  
            //    q1 = 4;
            //if (x2 - xc > 0 && y2 - yc > 0)         //第一象限  
            //    q2 = 1;
            //else if (x2 - xc < 0 && y2 - yc > 0)    //第二象限  
            //    q2 = 2;
            //else if (x2 - xc < 0 && y2 - yc < 0)    //第三象限  
            //    q2 = 3;
            //else                                    //第四象限  
            //    q2 = 4;
            //return q1 == q2;

            if (Math.Sign(x1 - xc) == 0 && Math.Sign(y1 - yc) == Math.Sign(y2 - yc)) return true;
            if (Math.Sign(y1 - yc) == 0 && Math.Sign(x1 - xc) == Math.Sign(x2 - xc)) return true;
            if (Math.Sign(x2 - xc) == 0 && Math.Sign(y1 - yc) == Math.Sign(y2 - yc)) return true;
            if (Math.Sign(y2 - yc) == 0 && Math.Sign(x1 - xc) == Math.Sign(x2 - xc)) return true;
            


            return Math.Sign(x1 - xc) == Math.Sign(x2 - xc) && Math.Sign(y1 - yc) == Math.Sign(y2 - yc);
        }
    }
}
